1 // --------------------------------------------------------------------------------------------------------------------
2 // <copyright company=
"Exit Games GmbH">
3 // Exit Games GmbH,
2012
4 // </copyright>
5 // <summary>
6 // TimeKeeper Helper. See
class description.
7 // </summary>
8 // <author>developer@exitgames.com</author>
9 // --------------------------------------------------------------------------------------------------------------------

10
11 namespace
ExitGames.Client.DemoParticle
12 {
13     
using System;
14
15     ///
<summary>
16     ///
A utility class that turns it's ShouldExecute property to true after a set interval time has passed.
17     ///
</summary>
18     ///
<remarks>
19     ///
TimeKeepers can be useful to execute tasks in a certain interval within a game loop (integrating a recurring task into a certain thread).
20     ///
21     ///
An interval can be overridden, when you set ShouldExecute to true.
22     ///
Call Reset after execution of whatever you do to re-enable the TimeKeeper (ShouldExecute becomes false until interval passed).
23     ///
Being based on Environment.TickCount, this is not very precise but cheap.
24     ///
</remarks>
25     
public class TimeKeeper
26     {
27         
private int lastExecutionTime = Environment.TickCount;
28         
private bool shouldExecute;
29
30         ///
<summary>Interval in which ShouldExecute should be true (and something is executed).</summary>
31         
public int Interval { get; set; }
32
33         ///
<summary>A disabled TimeKeeper never turns ShouldExecute to true. Reset won't affect IsEnabled!</summary>
34         
public bool IsEnabled { get; set; }
35
36         ///
<summary>Turns true of the time interval has passed (after reset or creation) or someone set ShouldExecute manually.</summary>
37         ///
<remarks>Call Reset to start a new interval.</remarks>
38         
public bool ShouldExecute
39         {
40             
get { return (this.IsEnabled && (this.shouldExecute || (Environment.TickCount - this.lastExecutionTime > this.Interval))); }
41             
set { this.shouldExecute = value; }
42         }

43
44         ///
<summary>
45         ///
Creates a new TimeKeeper and sets it's interval.
46         ///
</summary>
47         ///
<param name="interval"></param>
48         
public TimeKeeper(int interval)
49         {
50             
this.IsEnabled = true;
51             
this.Interval = interval;
52         }

53
54         ///
<summary>ShouldExecute becomes false and the time interval is refreshed for next execution.</summary>
55         ///
<remarks>Does not affect IsEnabled.</remarks>
56         
public void Reset()
57         {
58             
this.shouldExecute = false;
59             
this.lastExecutionTime = Environment.TickCount;
60         }
61     }
62 }


--------------------------------------------------------------------------------------------------------------------

Exit Games GmbH, 2012

TimeKeeper Helper. See class description.

developer@exitgames.com

--------------------------------------------------------------------------------------------------------------------

A utility class that turns it's ShouldExecute property to true after a set interval time has passed.

TimeKeepers can be useful to execute tasks in a certain interval within a game loop (integrating a recurring task into a certain thread).

An interval can be overridden, when you set ShouldExecute to true.

Call Reset after execution of whatever you do to re-enable the TimeKeeper (ShouldExecute becomes false until interval passed).

Being based on Environment.TickCount, this is not very precise but cheap.

Interval in which ShouldExecute should be true (and something is executed).

A disabled TimeKeeper never turns ShouldExecute to true. Reset won't affect IsEnabled!

Turns true of the time interval has passed (after reset or creation) or someone set ShouldExecute manually.

Call Reset to start a new interval.

Creates a new TimeKeeper and sets it's interval.

ShouldExecute becomes false and the time interval is refreshed for next execution.

Does not affect IsEnabled.




Trò chơi Tic-Tac-Toe, game đánh caro full source code 53.593 lượt xem

Gõ tìm kiếm nhanh...